﻿using System.Collections.Generic;
using DimOS.Constants;
using DimOS.Internals;
using HAL = Cosmos.Hardware;
using TERM = DimOS.DimSH.Terminal;

namespace DimOS.H
{
    public static class UnitTests
    {
        public static void Test()
        {
            var errors = new List<Error>();
//                DimL.Engine.Process(@"
//function bubblesort(arr)
//{
//    # (i = 0; i < size(arr); i++) {loop (j = 0; j < size(arr) - i - 1; j++) {if (arr[j] > arr[j+1]) {temp = arr[j]; arr[j] = arr[j+1]; arr[j+1] = temp; }}};
//    return arr;
//}
//arr = 467;
//@(<<arr); @(>>arr);");
                //Engine.Process("function another(go) { a = go / 0; return a;} function car(param) { b = another(param); return b; } try(i); doop = car(3);} {print(\"eh: \");}");
                //Engine.Process("a = 4; b = 5; ?(a <= b) ? (a == b)}} print(a+b); ?? (a > b) print(b); ???(a == b) print(\"success\"); ?? print(\"case\");");
                    //Engine.Process("loop (i :: 1)};}}} #(i :: 1) loop (i :: 5) if (i == 5) print(\"SPEcIAL\"); ?? print(i); print(\"FINISHED\");");
//                DimL.Engine.Process("a = 0; b = 0; x = 5; y = 5; i = -1; # (x == y) ? (a == b) {# (a < 3) {# (b :: 6) ? (b % 2 == 0) print(b + \": even\"); ?? print(b); a++; };};;; ??{print(\"GOOD\"); !$\"exception\"; print(a);}");
                 //Engine.Process("#;](i::1##q?0) print(i); print(\"FINISHED\")");
//                DimL.Engine.Process("i = \"test\"; print  (i); @(i); @  (i, 1); print  (2  ,6); print i; print(\"new\"); printi;");
//                DimL.Engine.Process("a = 5; b = 5; if(a > b) print(\"case 1\"); ??(a == b && a == 5) print(\"whoop\"); ?? print(\"case 2\"); print(\"fine\"); print(& + \"==============\");");
                // DimL.Engine.Process("print (\"start\"); print (2 ,3); dim.new { s.d arg another {print( 2, 8); dim.lol eh pop; dim.lol eh pop; print(2  ,3) } {print(   2,  3)}    }    {dim.eh new arg; print( \"new\") ; }; print  ( \"doop\"  , \"end\" );");
                 //DimL.Engine.Process("print(\"start\"  )  ; print (2 ,3 ); dim.new eh {dim.lol eh {dim {s.e nah {print( 2 , 3) }} {print( 2 , 3) ;} {s.e nah {wha;}}}};  print(  \"start\"  )  ; print (2 ,3 );");
                 //DimL.Engine.Process("print(\"start\"  )  ; print (2 ,3 ); dim.new eh {dim.lol eh {dim {s.e nah {print( 2 , 3) }   } {print( 2 , 3) ;} {s.e nah {wha; dim new { print (2  ,5); try{}{}  print( 2 , 6); g.e pop dop}; print(2  ,4  )}}  } };  print(  \"start\"  )  ; print (2 ,3 );");


            //Engine.Process("@(\"some text\"); dim.old some text;");
           // Engine.Process("d = 1; di = 0; ?(d && !di) @(\"success\"); ?;;](!(!d && di)) @(\"fail\"); ?\"\".!;;");

            //TERM.WriteLine("START: " + HAL.RTC.Minute.ToString().PadLeft(2, '0') + Separators
            //    .TimeDelimiter + HAL.RTC.Second.ToString().PadLeft(2, '0'));


            //Engine.Process("a = {1,2,3,4}; b = {5,6,7,8}; @((a+b)/1);");
            //DimL.Engine.Process("a = 500000; @(a * 2); @(a / 2); @(a * 2); @(a / 2); @(a * 2); @(a / 2); @(a * 2); @(a / 2);@(a * 2); @(a / 2); @(a * 2); @(a / 2); @(a * 2); @(a / 2); @(a * 2); @(a / 2);@(a * 2); @(a / 2); @(a * 2); @(a / 2); @(a * 2); @(a / 2); @(a * 2); @(a / 2);@(a * 2); @(a / 2); @(a * 2); @(a / 2); @(a * 2); @(a / 2); @(a * 2); @(a / 2);@(a * 2); @(a / 2); @(a * 2); @(a / 2); @(a * 2); @(a / 2); @(a * 2); @(a / 2);@(a * 2); @(a / 2); @(a * 2); @(a / 2); @(a * 2); @(a / 2); @(a * 2); @(a / 2);@(a * 2); @(a / 2); @(a * 2); @(a / 2); @(a * 2); @(a / 2); @(a * 2); @(a / 2);@(a * 2); @(a / 2); @(a * 2); @(a / 2); @(a * 2); @(a / 2); @(a * 2); @(a / 2);@(a * 2); @(a / 2); @(a * 2); @(a / 2); @(a * 2); @(a / 2); @(a * 2); @(a / 2);@(a * 2); @(a / 2); @(a * 2); @(a / 2); @(a * 2); @(a / 2); @(a * 2); @(a / 2);@(a * 2); @(a / 2); @(a * 2); @(a / 2); @(a * 2); @(a / 2); @(a * 2); @(a / 2);@(a * 2); @(a / 2); @(a * 2); @(a / 2); @(a * 2); @(a / 2); @(a * 2); @(a / 2);@(a * 2); @(a / 2); @(a * 2); @(a / 2); @(a * 2); @(a / 2); @(a * 2); @(a / 2);@(a * 2); @(a / 2); @(a * 2); @(a / 2); @(a * 2); @(a / 2); @(a * 2); @(a / 2);@(a * 2); @(a / 2); @(a * 2); @(a / 2); @(a * 2); @(a / 2); @(a * 2); @(a / 2);");


            //TERM.WriteLine("END: " + HAL.RTC.Minute.ToString().PadLeft(2, '0') + Separators
            //    .TimeDelimiter + HAL.RTC.Second.ToString().PadLeft(2, '0'));

//            Engine.Process(@"
//$IsPrime(n)
//{
//	?(n < 2) $$0;
//	?(n < 4) $$1;
//	?(n % 2 == 0) $$0;
//	
//	root = ceiling(sqrt(n));
//	
//	#(i = 3; i <= root; i += 2) ?(n % i == 0) $$0;
//	$$1;
//}
//#(i :: 15)
//@(i, IsPrime(i) :: "" is Prime"" :: ""is not Prime"",&);", ref errors);
//            Engine.Process(@"
//test = ["">home>tmp>coverage>test"",
//"">home>tmp>covert>operator>test"",
//"">home>tmp>covern>members>null>""];
////@test;
//$CommonPath(test)
//{
//   r = """"; t = 0; #(path :: test)
//   { chunks[t] = path/"">""; t++; }
//
//   #(i = 0; i < &(chunks[0]); i++)
//      { 
//            if (chunks[0][i] != cunks[1][i]) @""wha"";
//            //#(j = 1; j < 3; j++) { b = &(chunks[j]); if (i >= b) $$r; }
//            //r += chunks[0][i] + "">"";
//      }
//   $$r;
//}
//
//@(CommonPath(test));
//", ref errors);
            Engine.Process(@"
test = ["">home>tmp>coverage>test"",
"">home>tmp>covert>operator>test"",
"">home>tmp>covern>members>null>""];

$CommonPath(list)
{ r = """"; ?(&(list) == 0) $$r; tmp
  = 0; l = list[0]; #(i::&(l) - 1) {
  #(j::list) ?(i !< &(j) || (l[i]) !~
  (j[i])) $$!@(r, 0, tmp); @""""; ?((l[i]) == "">"") tmp = i; r += l[i];
  } $$r; 
}
@(CommonPath(test),&);
", ref errors);

            //Terminal.WriteLine("0001".Increment().Increment().Increment().Increment().Decrement().Decrement().Decrement().Decrement());
            //Terminal.WriteLine("aab2z".Increment().Increment().Increment().Increment().Decrement().Decrement().Decrement().Decrement());
            //Terminal.WriteLine("0009".Increment().Increment().Increment().Increment().Decrement().Decrement().Decrement().Decrement());
            //Terminal.WriteLine("zz".Increment().Increment().Increment().Increment().Decrement().Decrement().Decrement().Decrement());
            //Terminal.WriteLine("999".Increment().Increment().Increment().Increment().Decrement().Decrement().Decrement().Decrement());
            //Terminal.WriteLine("Zzzzyz".Increment().Increment().Increment().Increment().Decrement().Decrement().Decrement().Decrement());
        }
    }
}
